package com.sx.manage.controller.function;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sx.manage.biz.function.button.IMFunctionButtonBiz;
import com.sx.manage.controller.base.MBaseController;
import com.sx.manage.service.function.IMBaseFunctionButtonInfoService;
import com.sx.manage.service.function.IMBaseFunctionInfoService;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.manage.mybatis.form.function.MFunctionButtonInfoForm;
import com.sx.model.manage.mybatis.vo.function.MFuncButtonVO;
import com.sx.model.manage.mybatis.vo.function.MFunctionInfoVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;
import com.sx.model.manage.mybatis.vo.result.ResultObjectVO;



/**
 * 详细功能信息 控制器
 * @author zhenzhanlong
 *
 */
@Controller
@RequestMapping("/function_button")
public class MFunctionButtonInfoController extends MBaseController{
	/**
	 * 日志
	 */
	private Logger _log = LoggerFactory.getLogger(this.getClass());
	
	@Resource(name="mBaseFunctionButtonInfoServiceImpl")
	public  IMBaseFunctionButtonInfoService mBaseFunctionButtonInfoServiceImpl;
	
	@Resource(name="mBaseFunctionInfoServiceImpl")
	private IMBaseFunctionInfoService mBaseFunctionInfoServiceImpl;
	
	@Resource(name="functionButtonBizImpl")
	private IMFunctionButtonBiz functionButtonBizImpl;
	/***
	 * 功能信息列表
	 * @return
	 */
	@RequestMapping(value="button_index_view/{function_id}")
	public ViewAndModel button_index_view(@PathVariable Long function_id){
		_log.debug(" MFunctionButtonController 内 functionButtonIndex 方法调用");
			
		ViewAndModel funView = new ViewAndModel(request,cache);
						funView.setViewName("function/button/menuList");
		//查询功能信息			
		ResultObjectVO<MFunctionInfoVO>	functionResult = mBaseFunctionInfoServiceImpl.get_functionById(function_id);
		funView.addObject("functionVO", functionResult.getObjVo());
		return funView;
		
	}
	
	/**
	 * 功能信息添加界面
	 * @param form
	 * @return
	 */
	@RequestMapping(value="view_add/{function_id}")
	public ViewAndModel view_add(@PathVariable Long function_id){
		_log.debug(" MFunctionButtonController 内 toViewAdd 方法调用");
		ViewAndModel funView = new ViewAndModel(request,cache);
					    funView.setViewName("function/button/addbutMenu");
					    
						//查询功能信息			
		ResultObjectVO<MFunctionInfoVO>	functionResult = mBaseFunctionInfoServiceImpl.get_functionById(function_id);
		funView.addObject("functionVO", functionResult.getObjVo() );
		return funView;
	}
	
	/**获取详细功能信息列表*/
	@RequestMapping(value="view_edit/{id}")
	public ViewAndModel view_edit(@PathVariable Long id){
		_log.debug(" toViewEdit 内 toViewAdd 方法调用");
		ViewAndModel funView = new ViewAndModel(request,cache);
						funView.setViewName("function/button/editButMenu");
		//查询按钮信息			
		ResultObjectVO<MFuncButtonVO> buttonResult = this.mBaseFunctionButtonInfoServiceImpl.queryButtonById(id);
		
		funView.addObject("buttonVO", buttonResult.getObjVo() );
		//查询模块信息
		ResultObjectVO<MFunctionInfoVO> result = mBaseFunctionInfoServiceImpl.get_functionById(buttonResult.getObjVo().getFunction_id());
		funView.addObject("functionVO", result.getObjVo() );	
		
		return funView;
	}
	
	/**功能按钮保存*/
	@RequestMapping(value="func_button_save")
	public  @ResponseBody ResultBooleanVO func_button_save( MFunctionButtonInfoForm form ,BindingResult errors){
		_log.debug(" toViewEdit 内 functionButtonSave 方法调用");
		//验证 添加的数据格式是否正确
		String error = this.fieldValidate(form, errors); 
		if( null != error){
			return new  ResultBooleanVO(false,null,error);
		}
		return this.functionButtonBizImpl.functionButtonSave(form,loginConsumer());
	}
	
	/**获取详细功能信息列表*/
	@RequestMapping(value="func_button_list")
	@ResponseBody
	public ResultListVO<MFuncButtonVO> func_button_list(MFunctionButtonInfoForm form){
		_log.debug(" toViewEdit 内 functionButtonList 方法调用");
		return mBaseFunctionButtonInfoServiceImpl.queryButtonList(form);
	}
	
	/**获取模块信息列表*/
	@RequestMapping(value="func_button_page")
	@ResponseBody
	public ResultListVO<MFuncButtonVO> func_button_page(MFunctionButtonInfoForm form){
		_log.debug(" toViewEdit 内 functionButtonPage 方法调用");
		return mBaseFunctionButtonInfoServiceImpl.queryButtonPage(form);
	}
	
	/****启用**/
	@RequestMapping(value="func_button_enable")  
	@ResponseBody
	public ResultBooleanVO func_button_enable(Long[] ids){
		_log.debug(" toViewEdit 内 functionButtonEnable 方法调用");
		return functionButtonBizImpl.functionButtonStatusEnable(ids,loginConsumer());
	} 
	/****禁用 @PathVariable  */
	@RequestMapping(value="func_button_disable")  
	@ResponseBody
	public ResultBooleanVO func_button_disable(Long[] ids ){
		_log.debug(" toViewEdit 内 functionButtonDisable 方法调用");
		return functionButtonBizImpl.functionButtonStatusDisable(ids, loginConsumer());
	} 
	/**** 删除数据  */
	@RequestMapping(value="func_button_delete")  
	@ResponseBody
	public ResultBooleanVO func_button_delete(Long[] ids ){
		_log.debug(" toViewEdit 内 functionButtonDelete 方法调用");
		return functionButtonBizImpl.functionButtonStatusDisable(ids, loginConsumer());
	} 
	
	public IMBaseFunctionButtonInfoService getmBaseFunctionButtonInfoServiceImpl() {
		return mBaseFunctionButtonInfoServiceImpl;
	}

	public void setmBaseFunctionButtonInfoServiceImpl(IMBaseFunctionButtonInfoService mBaseFunctionButtonInfoServiceImpl) {
		this.mBaseFunctionButtonInfoServiceImpl = mBaseFunctionButtonInfoServiceImpl;
	}

	public IMBaseFunctionInfoService getmBaseFunctionInfoServiceImpl() {
		return mBaseFunctionInfoServiceImpl;
	}

	public void setmBaseFunctionInfoServiceImpl(IMBaseFunctionInfoService mBaseFunctionInfoServiceImpl) {
		this.mBaseFunctionInfoServiceImpl = mBaseFunctionInfoServiceImpl;
	}

	public IMFunctionButtonBiz getFunctionButtonBizImpl() {
		return functionButtonBizImpl;
	}

	public void setFunctionButtonBizImpl(IMFunctionButtonBiz functionButtonBizImpl) {
		this.functionButtonBizImpl = functionButtonBizImpl;
	}
	

	
}
